#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/kthread.h>
#include <linux/smp_lock.h>
#include <linux/errno.h>
#include <linux/types.h>
#include <linux/sched.h>
#include <linux/pid.h>
#include <linux/netdevice.h>
#include <linux/ip.h>
#include <linux/in.h>
#include <linux/delay.h>
#include <linux/string.h>


#include<linux/fs.h>
#include<asm/segment.h>
#include<linux/buffer_head.h> 


#include "handling.h"


//////////////////////////////////////////////////////DEBUG CEZ SIET////////////////////////////////////////
/*
phs_debug(DBG_IP, "moj vypis kam si dam nieco inteligentne");
*/
//////////////////////////////////////////////////////Koniec debugu cez siet////////////////////////////////



char *tmppole;
//struct task_struct *hello_thread;
//int run_hello;
static struct timer_list my_hello_timer;
//static struct timer_list sw_out_timer;
//static struct timer_list sw_in_timer;
static void init_hello_timer(void);

void phs_debug(char* ipcka, char* vypis) {
	int tmp = pf_send_data(htonl(get_int_ip(ipcka)), (unsigned char *) vypis, strlen(vypis));
	if(0 > tmp){  //Dufam ze odosle hlasku 
                printk(KERN_INFO": DBG: dojebalo sa odoslanie debugu sme v <> %d\n", tmp);
        }
}


void send_negative_phs_ack_write_request(struct request* req){
	printk(KERN_INFO" DBG: negative_phs_ack_write\n");
	phs_debug(DBG_IP, " DBG: negative_phs_ack_write\n");
	phs_ack_write_request(req, -1);
}

void send_negative_phs_ack_read_request(struct request* req){

	phs_ack_read_request(req, -50, NULL, 0);
}

int handle_hello(unsigned int source_ip, SwapPacket *packet){
	
	struct n_ent *n_etmp;
	
//debug send_swap_out_request(struct request *req, u32 offset_interny, u32 nBytes) 		
	struct request *nreq;
	u32 noffset=0, nnbytes=512;
	char *tmpbuff;

	
	printk(KERN_INFO"DBG: handle_hello start\n");
	n_etmp = (struct n_ent *)vmalloc(sizeof(struct n_ent));
	if (NULL == n_etmp) {
		printk(KERN_INFO ": ERR: ran out of memory allocating a n_etmp\n");

		return -1;
        }
        else {
		n_etmp->neigh_id_o = source_ip;
		n_etmp->free_space_o = packet->space;
		n_etmp->network_load_o = packet->network_load;
		n_etmp->cpu_load_o = packet->cpu_load;
		n_etmp->num_proc_o = packet->num_proc;
		n_etmp->last_upd_o = 124300;
		
//		printk(KERN_INFO"DBG: adding to nlist\n");
		insert_nent(n_etmp);
//		printk(KERN_INFO"DBG: after add find best ID = %u\n", find_best_nent());

//debug send_swap_out_request(struct request *req, u32 offset_interny, u32 nBytes) 		
		nreq = (struct request *)vmalloc(sizeof(struct request));
		tmpbuff = vmalloc(512);
		memset(tmpbuff, 0x41, 512);
		nreq->buffer = tmpbuff;
		noffset = (u32) tmpbuff;
		printk(KERN_INFO"DBG: send_swap_out_req(tmpbuff= %s)\n", tmpbuff);
		printk(KERN_INFO"DBG: send_swap_out_req(nreq= %u noffset= %u nnbytes= %u)\n", ((u32 )(nreq)), noffset, nnbytes);
		send_swap_out_request(nreq, noffset, nnbytes);
		
		vfree(tmpbuff);
		vfree(nreq);
//		insert_n_entry(n_etmp);
		return 0;
	}
}

int handle_swap_out_request(unsigned int source_ip, SwapPacket *packet){

	int i;	
	u32 *pointer_na_datta;

	printk(KERN_INFO": DBG: handle_swap_out_request start\n");
	phs_debug(DBG_IP, "DBG: handle_swap_out_request start");
	
	i = phs_save_data(packet->data, 512, pointer_na_datta);          //osetrit negativne  konecne osetrene :-) 
	
	phs_debug(DBG_IP, "DBG: handle_swap_out_request po phs_save_data");
	send_swap_out_reply(i, packet->page_id, source_ip, pointer_na_datta, packet->seq_num); 
	
	

return 0;	
}

int handle_swap_out_reply(unsigned int source_ip, SwapPacket *packet){
	
	struct pt_ent_xyz *news;
	struct reqtimer *pointer;

	pointer = (struct reqtimer *)(packet->seq_num);	
	news = (struct pt_ent_xyz *)vmalloc(3 * sizeof(int));



	if(packet->flag_ack == 1){
		if (!news) {
			printk(KERN_INFO ": ERR: ran out of memory allocating a new\n");
			phs_debug(DBG_IP, "ERR: ran out of memory allocating a new");
			phs_ack_write_request((struct request *)(pointer->pointer_req), -1);
			return -1;
		}
		else {
			news->page_id_o = packet->page_id;
			news->node_id_o = source_ip;
			news->address_o = packet->mem_address;


	////////////int pt_insert_entry(struct pt_ent_xyz *entry);
			pt_insert_entry(news);

			printk(KERN_INFO ": DBG: handle_swap_out_reply pred vladovou fciou\n");
			phs_debug(DBG_IP, "DBG: handle_swap_out_reply pred vladovou fciou");

			phs_ack_write_request((struct request *)(pointer->pointer_req), 1);
			printk(KERN_INFO ": DBG: handle_swap_out_reply za vladovou fciou\n");
			phs_debug(DBG_IP, "DBG: handle_swap_out_reply za vladovou fciou");
			
			if((pointer->pointer_timer) == 0){
				printk(KERN_INFO ": DBG: handle_swap_out_reply pointer timer = 0\n");
				phs_debug(DBG_IP, "DBG: handle_swap_out_reply pointer timer = 0");
			}
			else{
				del_timer_sync((struct timer_list *)(pointer->pointer_timer));
				vfree(pointer);		//skontrolovat ci nie je null pointer a nie 0?
			}
			printk(KERN_INFO ": DBG: handle_swap_out_reply za deletom timeru\n");
			phs_debug(DBG_IP, "DBG: handle_swap_out_reply za deletom timeru");

			return 0;
		}
	
	}
	else{
		printk(KERN_INFO ": ERR: handle swap_out_reply_dosiel flag 0\n");

		phs_debug(DBG_IP, "ERR: handle swap_out_reply_dosiel flag 0");
		phs_ack_write_request((struct request *)(pointer->pointer_req), -1);	
		return -1;

	}


	
}

int handle_swap_in_request(unsigned int source_ip, SwapPacket *packet){

	char *tmp_buffer = (char *) &(packet->data);
	u32 tmp_mem_address;


	if (1 == phs_read_data( tmp_buffer, &(packet->mem_address), 512) ) {
		
		send_swap_in_reply(1, packet->page_id, source_ip, tmp_buffer, packet->seq_num);
		phs_debug(DBG_IP, "moj vypis kam si dam nieco inteligentne");

	}  
	else {	
		send_swap_in_reply(-1, packet->page_id, source_ip, tmp_buffer, packet->seq_num); //send negative reply	

		phs_debug(DBG_IP, "moj vypis kam si dam nieco inteligentne");

	}


return 0;	
}

int handle_swap_in_reply(unsigned int source_ip, SwapPacket *packet){

	struct reqtimer *pointer = (struct reqtimer *)(packet->seq_num);



if(packet->flag_ack == 1){
	
	if (1 == phs_ack_read_request((struct request *)(pointer->pointer_req), 0, packet->data, 512)){ //da data OS a vymaze zaznam z tabulky
		pt_delete_entry(packet->page_id);
		del_timer_sync((struct timer_list *)(pointer->pointer_timer));
		vfree(pointer);
		return 0;	
	}
	else{   //doplnit daco ??? 
		del_timer_sync((struct timer_list *)(pointer->pointer_timer));
		vfree(pointer);
		return -1;
	}

	
}

else{
	printk(KERN_INFO ": ERR: handle swap_in_reply_dosiel flag 0\n");

	phs_debug(DBG_IP, "ERR: handle swap_in_reply_dosiel flag 0");

	phs_ack_read_request((struct request *)(pointer->pointer_req), -50, NULL, 0);
	del_timer_sync((struct timer_list *)(pointer->pointer_timer));
	vfree(pointer);
	return -1;

}
	
}


// ***************************
static void phs_hello_func(unsigned long ptr){
	send_hello();
	printk(KERN_INFO ": timer zbehol co je fajn");

//	phs_debug(DBG_IP, "timer zbehol co je fajn");

	init_hello_timer();
}
// ***************************

static void init_hello_timer(void) {
	init_timer(&my_hello_timer);
	my_hello_timer.function = (void *) phs_hello_func;
	my_hello_timer.expires = jiffies + msecs_to_jiffies(5000);
	add_timer(&my_hello_timer);
}

int hello_init(void){
// ***************************
/*	run_hello = 1;
	hello_thread = kthread_run((void *)hello_func, NULL, "hello_tread");
	if (IS_ERR(hello_thread))
	{
		printk(KERN_INFO"DBG: hello thread create unsuccessful\n");
		return -1;
	}
*/
	
//	create_nlist();
//	pt_create_page_table ();
	//tmppole = (char *)vmalloc(512 * sizeof(char));
	//timer

	
	init_hello_timer();
	printk(KERN_INFO"DBG: hello initiated\n");
	phs_debug(DBG_IP, "DBG: hello initiated");

	return 0;
	//***************************/
}

void hello_exit(void)
{
	del_timer_sync(&my_hello_timer);
	//del_timer_sync(&sw_out_timer);
	//del_timer_sync(&sw_in_timer);
	printk(KERN_INFO"DBG: hello uninitiated\n");
	phs_debug(DBG_IP, "DBG: hello uninitiated");

}

int send_hello(){
	SwapPacket *x;
	
	x = (SwapPacket *) kmalloc(sizeof(SwapPacket), GFP_ATOMIC);
	if (x == NULL) {
		printk(KERN_ERR "DBG: Nedostal som pamat na SwapPacket\n");
		return -1;
	}
	memset(x, 0, sizeof(SwapPacket));
	/*struct SwapPacket *packet;
	packet = (struct SwapPacket *)vmalloc(sizeof(struct SwapPacket));
	if (NULL == packet) {
    		printk(KERN_INFO": ERR: ran out of memory allocating a packet\n");
        	return 1;
    	}*/	
	
	/*x.type = 2;
	x.flag_ack = 1;
	x.flag_nack = 1;
	x.ip = get_int_ip(teip);
	x.checksum = 15;
	x.network_load = 16;
	x.cpu_load = 24;
	x.num_proc = 48;
	x.space = 643200;
	x.page_id = 0;
	x.seq_num = 123456789;
	x.mem_address = 0;

	printk(KERN_INFO": DBG: Hello sent\n");

	analyze((unsigned char *)&x, &packet);

	printk(KERN_INFO" DBG: paket: typ: %d\n", packet.type);
	printk(KERN_INFO" DBG: paket: ack: %d\n", packet.flag_ack);
	printk(KERN_INFO" DBG: paket: nack: %d\n", packet.flag_nack);
	printk(KERN_INFO" DBG: paket: chs: %d\n", packet.checksum);
	printk(KERN_INFO" DBG:  orig: ip: %d\n", x.ip);
	printk(KERN_INFO" DBG: paket: ip: %d\n", packet.ip);
	//printk(KERN_INFO" DBG: paket: ip: %s\n", get_str_ip(packet.ip));
	printk(KERN_INFO" DBG: paket: seq: %d\n", packet.seq_num);*/
	
	x->type = 1;
	x->flag_ack = 0;
	x->flag_nack = 0;
	//x.ip = get_int_ip(teip);
	x->checksum = 0;
	
	x->network_load = 0;
	x->cpu_load = 13;
//	x->cpu_load = load_avg_1 + 10*load_avg_5 + 100*load_avg_15;
	x->num_proc = 0;
	
	x->space = 123456;
//	x->space = free_mem;
	x->page_id = 0;
	x->seq_num = 0;
	x->mem_address = 0;

//	raw_data = (unsigned char *)&x;
	
	if(0 <= pf_send_hello((unsigned char *) x, sizeof(SwapPacket))){
		printk(KERN_INFO": DBG: Hello sent\n");

//debug - ak nefunguje siet, toto zavola handling na hello packet ktory sa odoslsal
//		handle_hello(get_int_ip(teip), &x);
	}
	else{
		printk(KERN_INFO": ERR: Hello not sent\n");
	}
	
	return 0;
}

int send_swap_out_request(struct request *req, u32 offset_interny, u32 nBytes){
	struct reqtimer *struct_of_pointers;
	SwapPacket x; 
	struct timer_list *packetTimer;
	struct SwapPacket *packet;

	packet = (struct SwapPacket *)vmalloc(sizeof(struct SwapPacket));
	    if (NULL == packet) {
	    	printk(KERN_INFO": ERR: ran out of memory allocating a packet\n");
		return 1;
	    }

	//char *teip = "192.168.1.72";   //ip napevno docasne   (hmm docasne napevno je dobry slovny zgrc :-) ) 
	//char *raw_data;
	
	printk(KERN_INFO": DBG: swap_out_request start\n");
	
	x.type = 2;  //swap out
	x.flag_ack = 0;
	x.flag_nack = 0;
	x.ip = find_best_nent();
	if ( 0 == x.ip) {
	

	printk(KERN_INFO": ERR: Swap_Req_Send Error nenasiel sa vhodny host\n");

	phs_debug(DBG_IP, "ERR: Swap_Req_Send Error nenasiel sa vhodny host");

	phs_ack_write_request(req, -1);		// hodi error niekomu inemu 
	return -1; 	
	//break; 

	}  //vybrat z nlist  dest_IP  osetrit negativne 
	
	printk(KERN_INFO"DBG: send_swap_out_request x.ip = %u\n", (x.ip));
	x.page_id = offset_interny;

	struct_of_pointers = (struct reqtimer *)vmalloc(sizeof(struct reqtimer));
	if (NULL == struct_of_pointers) {
		printk(KERN_INFO ": ERR: ran out of memory allocating a reqtimer\n");

		return -1;
        }
        else {
		// alokujem si pamat na timer
		packetTimer = (struct timer_list *) vmalloc(sizeof(struct timer_list));
		// overim si ci mam pamat dostupnu
		if (packetTimer == NULL) {
			// v tomto kroku nam system nealokoval pamat z nejakeho dovodu
			printk(KERN_ERR "packetTimer ERR: ran out of memory allocating a timer\n");
			phs_debug(DBG_IP, "packetTimer ERR: nedostali sme pamat");
		}
		init_timer(packetTimer); //inicializacia timeru
		packetTimer->function = (void *) send_negative_phs_ack_write_request; //nazov volanej funkcie po uplynuti timera
		packetTimer->data = (unsigned long) req; //parameter volanej funkcie
		packetTimer->expires = jiffies + msecs_to_jiffies(1000); //cas uplynutia timera = 1s
		add_timer(packetTimer); //pridanie timera do zoznamu
				

		struct_of_pointers->pointer_req = req;
		struct_of_pointers->pointer_timer = packetTimer;
	}
	
	x.seq_num = struct_of_pointers;
	
	//raw_data = req->buffer;
	//x.data = *raw_data;
	printk(KERN_INFO": DBG: swap_out_request pred memcpy\n");

	phs_debug(DBG_IP, "DBG: swap_out_request pred memcpy");
	memcpy(req->buffer, &x.data, 512);

	printk(KERN_INFO": DBG: swap_out_request pred IFom\n");

	printk(KERN_INFO": DBG: swap out request pred odoslanim ip= %u, page_id= %u, mem_address= %u\n", x.ip, x.page_id, x.mem_address);

	analyze((unsigned char *)&x , packet);

	printk(KERN_INFO": DBG: swap out request po analyze     ip= %u, page_id= %u, mem_address= %u\n", packet->ip, packet->page_id, packet->mem_address);
	

	if(0 <= pf_send_data(x.ip , (unsigned char *)&x , sizeof(SwapPacket))){
		printk(KERN_INFO": DBG: Swap_Req_Send\n");

		phs_debug(DBG_IP, " DBG: Swap_Req_Send");

		//start timer
		return 0;

	}
	else{
		printk(KERN_INFO": ERR: Swap_Req_Send Error nepodarilo sa odoslat\n");

		phs_debug(DBG_IP, "ERR: Swap_Req_Send Error nepodarilo sa odoslat");


		phs_ack_write_request(req, -1);	  // hodi error niekomu inemu 
		return -1; 	
		
	}


        //start timer ???
}


int send_swap_out_reply(int flag, int page_id, unsigned int dest_ip, u32 *fyzicka_addr, struct reqtimer* seqnumber){

	SwapPacket x;
	struct SwapPacket *packet;

	packet = (struct SwapPacket *)vmalloc(sizeof(struct SwapPacket));
	    if (NULL == packet) {
	    	printk(KERN_INFO": ERR: ran out of memory allocating a packet\n");
		return 1;
	    }

	
	printk(KERN_INFO": DBG: send_swap_out_reply start\n");

		phs_debug(DBG_IP, "DBG: send_swap_out_reply start");
	
	x.type = 3;  //swap out replay
	
	if (flag == 1){
		x.flag_ack = 1;
		x.flag_nack = 0;
	}
	else if (flag == -1){
		x.flag_ack = 0;
		x.flag_nack = 1;
	}
	x.mem_address = (u32) fyzicka_addr;
	x.page_id = page_id;
	x.seq_num = seqnumber;

	printk(KERN_INFO": DBG: swap out reply            ip= %u, page_id= %u, mem_address= %u\n", dest_ip, x.page_id, x.mem_address);




	analyze((unsigned char *)&x , packet);

	printk(KERN_INFO": DBG: swap out reply po analyze ip= %u, page_id= %u, mem_address= %u\n", packet->ip, packet->page_id, packet->mem_address);


	if(0 <= pf_send_data(dest_ip , (unsigned char *)&x , sizeof(SwapPacket))){
		printk(KERN_INFO": DBG: Swap_out_reply_Send\n");

		phs_debug(DBG_IP, "DBG: Swap_out_reply_Send");


		return 0;

	}
	else{
		printk(KERN_INFO": ERR: Swap_out_reply_Send Error nepodarilo sa odoslat\n");
		  // hodi error niekomu inemu 
		return -1; 	
		
	}





return 0;
}

int send_swap_in_request(struct request *req, u32 offset_interny, u32 nBytes){
	
	struct reqtimer *struct_of_pointers;
	struct timer_list *packetTimer; 

	struct pt_ent_xyz *tmpent = NULL;
	SwapPacket x;
	
	
	printk(KERN_INFO": DBG: swap_in_request start\n");

		phs_debug(DBG_IP, "DBG: swap_in_request start");

	x.type = 4;  //swap out
	x.flag_ack = 0;
	x.flag_nack = 0;
	
	if(-1 == pt_find_entry(offset_interny, tmpent)){
	
	tmppole = (char *)vmalloc(nBytes * sizeof(char));
	phs_ack_read_request(req, 0, tmppole, nBytes);	
	vfree(tmppole);
	}   //osetrit ak sa nenajde
	
	x.ip = tmpent->node_id_o;     //najde uzol v tabulke
	
	

	x.page_id = offset_interny;
	
	struct_of_pointers = (struct reqtimer *)vmalloc(sizeof(struct reqtimer));
	if (NULL == struct_of_pointers) {
		printk(KERN_INFO ": ERR: ran out of memory allocating a reqtimer\n");

		return -1;
        }
        else {
                // alokujem si pamat na timer
                packetTimer = (struct timer_list *) vmalloc(sizeof(struct timer_list));
                // overim si ci mam pamat dostupnu
                if (packetTimer == NULL) {
                        // v tomto kroku nam system nealokoval pamat z nejakeho dovodu
                        printk(KERN_ERR "packetTimer ERR IN: ran out of memory allocating a timer\n");
                        phs_debug(DBG_IP, "packetTimer ERR IN: nedostali sme pamat");
                }
		init_timer(packetTimer); //inicializacia timeru
		packetTimer->function = (void *) send_negative_phs_ack_read_request; //nazov volanej funkcie po uplynuti timera
		packetTimer->data = (unsigned long) req; //parameter volanej funkcie
		packetTimer->expires = jiffies + msecs_to_jiffies(1000); //cas uplynutia timera = 1s
		add_timer(packetTimer); //pridanie timera do zoznamu
				

		struct_of_pointers->pointer_req = req;
		struct_of_pointers->pointer_timer = packetTimer;
	}
	x.seq_num = struct_of_pointers;

	x.mem_address = tmpent->address_o;


	//raw_data = req->buffer;
	//x.data = *raw_data;
	//printk(KERN_INFO": DBG: swap_in_request pred memcpy\n");
	//memcpy(req->buffer, &x.data, 512);

	printk(KERN_INFO": DBG: swap_in_request pred IFom\n");

		phs_debug(DBG_IP, "DBG: swap_in_request pred IFom");


	if(0 <= pf_send_data(x.ip , (unsigned char *)&x , sizeof(SwapPacket))){
		printk(KERN_INFO": DBG: Swap_in_Req_Send\n");

		phs_debug(DBG_IP, "DBG: Swap_in_Req_Send");


		return 0;

	}
	else{
		printk(KERN_INFO": ERR: Swap_in_Req_Send Error nepodarilo sa odoslat\n");

		phs_debug(DBG_IP, "ERR: Swap_in_Req_Send Error nepodarilo sa odoslat");
		//phs_ack_write_request(req, -1);	  // hodi error niekomu inemu 
		return -1; 	
		
	}

	
	//start timer ???

return 0;
}

int send_swap_in_reply(int flag, int page_id, unsigned int dest_ip, char *data, struct reqtimer* seqnumber){


	SwapPacket x;
	
	printk(KERN_INFO": DBG: send_swap_in_reply start\n");

		phs_debug(DBG_IP, "DBG: send_swap_in_reply start");


	
	x.type = 5;  //swap out replay
	
	if (flag == 1){
		x.flag_ack = 1;
		x.flag_nack = 0;
	}
	else if (flag == -1){
		x.flag_ack = 0;
		x.flag_nack = 1;
	}
	x.page_id = page_id;
	x.seq_num = seqnumber;
	
	printk(KERN_INFO": DBG: swap_in_reply pred memcpy\n");

		phs_debug(DBG_IP, "DBG: swap_in_reply pred memcpy");


	memcpy(&x.data, data, 512);


	if(0 <= pf_send_data(dest_ip , (unsigned char *)&x , sizeof(SwapPacket))){
		printk(KERN_INFO": DBG: Swap_in_Reply_Send\n");

		phs_debug(DBG_IP, "DBG: Swap_in_Reply_Send");


		return 0;

	}
	else{
		printk(KERN_INFO": ERR: Swap_in_Reply_Send Error nepodarilo sa odoslat\n");
		  // hodi error niekomu inemu 
		return -1; 	
		
	}


return 0;
}

int switch_handler(unsigned int source_ip, unsigned char *raw_data){
	struct SwapPacket *packet;

	printk(KERN_INFO": DBG: switch handler started\n");
	phs_debug(DBG_IP, "DBG: switch handler started");


packet = (struct SwapPacket *)vmalloc(sizeof(struct SwapPacket));
    if (NULL == packet) {
    	printk(KERN_INFO": ERR: ran out of memory allocating a packet\n");
        return 1;
    }

analyze(raw_data, packet);

printk(KERN_INFO": DBG: switch_handler ip= %u, page_id= %u, mem_address= %u\n", packet->ip, packet->page_id, packet->mem_address);

switch(packet->type){
	case 1: printk(KERN_INFO": DBG: switch handle helo\n"); 
		phs_debug(DBG_IP, "DBG: switch handle helo"); 
		handle_hello(source_ip, packet); break;//- hello
 	case 2: printk(KERN_INFO": DBG: switch handle swap out req\n");
		phs_debug(DBG_IP, "DBG: switch handle swap out req");
		handle_swap_out_request(source_ip, packet); break;//- swap-out request
	case 3: printk(KERN_INFO": DBG: switch handle swap out rep\n"); 
		phs_debug(DBG_IP, "DBG: switch handle swap out rep");
		handle_swap_out_reply(source_ip, packet); break;//- swap-out reply
	case 4: printk(KERN_INFO": DBG: switch handle swap in req\n"); 
		phs_debug(DBG_IP, "DBG: switch handle swap in req");
		handle_swap_in_request(source_ip, packet); break;//- swap-in request
	case 5: printk(KERN_INFO": DBG: switch handle swap in rep\n"); 
		phs_debug(DBG_IP, "DBG: switch handle swap in rep");
		handle_swap_in_reply(source_ip, packet); break;//- swap-in reply
	
	default:printk(KERN_INFO": DBG: switch handle default %d \n ",packet->type);
		return 1;
		break;
	}

	printk(KERN_INFO ": DBG: koniec switch_handler\n");
	phs_debug(DBG_IP, "DBG: koniec switch_handler");
	
return 0;	
}


